package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 *泛型的演示
 */
public class GenericDemo {
    public static void main(String[] args) {
        Collection<Point>a=new ArrayList<>();
        a.add(new Point(1,2));
        a.add(new Point(2,3));
        a.add(new Point(3,4));
        a.add(new Point(4,5));
        a.add(new Point(5,6));

        Iterator<Point>i=a.iterator();
        while(i.hasNext()){
            Point p=i.next();
            System.out.println(p);
        }



        for(Point p:a){
            System.out.println(p);
        }












        Collection<String> c=new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");

        //迭代器的泛型应该与集合中的类型一致
        Iterator<String>it=c.iterator();
        while (it.hasNext()){
           String str =it.next();
            System.out.println(str);
        }

        //迭代是即想循环又想操作集合里的变量
        //纯循环速度加快
        for(String cc:c){
            System.out.println(cc);
        }

    }
}
